"use strict";

var order = {
    "orderAmount":13.5
    ,"orderGoodsList":
        [
            {
                "name":'苹果',
                "price":15.69,
                "goodsId":'725674162412060672',
            },
            {
                "name":'苹果',
                "price":8.29,
                // "id":'725674162412060672',
            }
        ]
};
order ={};
/*
* 在商品列表页面 进行下单
*
* */
function saveOrder(goodsId){
    // jQuery 框架 提供的 $
    $.ajax({
        url: ctx + "/shop/order/saveOrder1",
        type: "post",
        data: JSON.stringify(order),
        contentType: "application/json;charset=UTF-8",
        async : false,
        success : function(result) {
            order = {};
            if(result.code== 0){
                layer.msg("保存成功！", {icon: 1, time: 1000}, function (){
                    // parent.window.location.reload();
                })
            }else{
                layer.msg("商品信息,保存失败！", {icon: 1, time: 1000}, function (){
                    // parent.window.location.reload();
                })
            }
        },
        error: function (e) {
            layer.msg(e, {icon: 5});
        }
    });
}


function addCart(price,name){
    // order.orderGoodsList.push({price,name});
    order.orderGoodsList || (order.orderGoodsList = []);
    // if(!order.orderGoodsList){
    //     order.orderGoodsList = [];
    // }
    order.orderAmount || (order.orderAmount = 0.00);
    order.orderGoodsList.push({price:price,name:name});
    order.orderAmount +=  parseFloat(price);

    console.log(order)

}